/**
 * @author banglong
 * @date 2016/8/23.
 */
define(['avalon', 'Layer', 'text!../html/index/bill/billListTemp.html!strip', 'billListApi', 'conditionsUtils',
    'tools', 'NewBill', 'depsSelectDialog', 'getApiConfig', 'getVmConfig', 'CommonBill', 'BillDetailDialog',
    'chooseCondition', 'text!../html/index/bill/billListOperate.html!strip', 'bus', 'AccountQuery', 
    'text!../html/index/bill/billListYgsqTemp.html!strip','laydate'],
  function (avalon, layer, htmlTemp, api, conditionsUtils, tools, NewBill, depsSelectDialog,
    getApiConfig, getVmConfig, CommonBill, BillDetailDialog, chooseCondition, billListOperateHtml, bus, AccountQuery,
    billListYgsqTemp) {

    return function () {
      var self = this;
      var runtimeParam;
      var getRuntimeParam = function () {
        return {
          timeObj: {},
          // 需要加入查询余额的 账册 数组 默认
          limitGoodsBookArr: ['000000000000CC', '000000000000TT', '000000000000WW', '000000000000ZZ']
        };
      };

      var billListVm;
      var getVmOption = function () {
        return {
          $id: 'receiveReceipt',
          breadcrumb: '',
          bills: [], // 单据列表
          billDetails: [],
          size: 30, // 大小
          pages: 0, // 页数
          count: 0, // 总数

          currentDept: {}, // 当前登录科室
          isProviderDept: false, // 是否是供应科室

          inputAccountLabelName: '入库科室账户：', // 名称
          showKsGroup: false, // 显示查询条件框
          showBillSN: false,
          tableComponentsID: ['billList', 'billListDetail'],

          columnNames: [], // 表格列名
          columnValueNames: [], // 表格值
          detailColumnNames: [], // 单据详情的表格列名
          detailColumnValueNames: [], // 单据详情的表格值

          entryStartDate: '', // 录入时间
          entryEndDate: '',
          sendStartDate: '', // 发送时间
          sendEndDate: '',
          outStartDate: '', // 出库时间
          outEndDate: '',

          inputAccount: '', //领用科室 or 出库科室 名称
          inputAccountID: '', //领用科室 or 出库科室 id
          ksGroup: '', // 科室组合
          ksGroupID: '', // 科室组合id
          BillSN: '', // 流水号

          status: '', // 状态拼音简写
          statusStr: [], // 状态中文
          BillType: '', // 单据状态
          AdditionalReasonType: '', // 来源
          hasInputAuth: false,
          hasSendAuth: false,

          isGYKS: false,
          colorDescription: '', // 颜色说明
          showQuery: false,
          IsQuery: false,

          operateHtml: billListOperateHtml, // 表格的操作
          operateCustomEvent: {},
          statusArr: [],
          // 查找
          search: function () {
            if (new Date(billListVm.entryStartDate) >= new Date(billListVm.entryEndDate)) {
              tools.alterError('开始时间不能大于或等于结束时间');
              return;
            }
            getALLReceipt(getSearchParam());
          },
          // 科室选择
          chooseDept: function (e) {
            // 科室选择框
            tools.throttle(runtimeParam.timeObj, function () {
              var deps = JSON.parse(localStorage.getItem('deps'));
              depsSelectDialog.init(deps,
                function (dep) {
                  billListVm.inputAccount = dep.Ksmc.trim();
                  billListVm.inputAccountID = dep.DeptAccountID;
                },
                billListVm.inputAccount);
            });
          },
          // 科室组合
          chooseDeptGroup: function (e) {
            // 科室组合选择框
            tools.throttle(runtimeParam.timeObj, function () {
              var param = {
                type: 5
              };
              param.chooseConditionsFunc = function (condition) {
                billListVm.ksGroup = condition.GroupName;
                billListVm.ksGroupID = condition.GroupSN;
              };
              param.searchValue = billListVm.ksGroup;
              chooseCondition.init(param);
            });
          },
          // 打开新建单据页面
          handleNewBill: function () { // 打开新建单据页面
            billListVm.checkAccountBalance(function () {
              tools.removeFirstChildNode(runtimeParam.main, documentNodeTree);
              billListVm.newBill();
            })
          },
          // 检查是否账册是否需要 判断余额
          checkAccountBalance: function (callback) {
            if (runtimeParam.limitGoodsBookArr.indexOf(runtimeParam.Openparm.GoodsBook) !== -1) {
              // 将 业务代码 与 视图界面分离
              bus.triggerHandler('billlist.checkGoodsBook', {
                vm: billListVm,
                param: runtimeParam,
                callback: callback,
                errorCallback: function () {
                  new AccountQuery().init({
                    deptAccountID: runtimeParam.InDeptAccountID,
                    goodsBookID: runtimeParam.Openparm.GoodsBook
                  });
                }
              });
            } else {
              // tools.removeFirstChildNode(runtimeParam.main, documentNodeTree);
              if (callback) {
                callback()
              }
            }
          },
          // 打开单据新增页面
          newBill: function () {
            new NewBill().init(runtimeParam.$main, {
              breadcrumb: billListVm.breadcrumb, //路径
              OutDeptAccount: runtimeParam.ProviderDeptAccount, // 出库科室信息
              InDeptAccount:runtimeParam.InDeptAccount,//跳转阳光采购
              init: true,
              Openparm: runtimeParam.Openparm,
              InDeptAccountID: runtimeParam.CurrentDeptID,
              BillType: runtimeParam.BillType, // 单据类型
              BillStatus: 'new', //单据状态
              statusStr: runtimeParam.statusStr, // 状态
              user: runtimeParam.user,
              isProviderDept: runtimeParam.isProviderDept,
              isGYKS: JSON.parse(JSON.stringify(billListVm.isGYKS)),
              bill: new CommonBill()
            /*  showMenu:runtimeParam.showMenu,
              checkBreadcrumb:runtimeParam.checkBreadcrumb*/
            });
          },
          // 查看
          viewDetail: function (index) {
            if (billListVm.IsQuery) {
              tools.throttle(runtimeParam.timeObj, function () {
                var bill = billListVm.bills[index].$model;
                if (!runtimeParam.BillDetailDialog) {
                  runtimeParam.BillDetailDialog = new BillDetailDialog();
                }
                runtimeParam.BillDetailDialog.init({
                  api: api,
                  isGYKS: billListVm.isGYKS,
                  BillType: runtimeParam.BillType,
                  bill: bill,
                  pushArray: function (result) {
                    billListVm.billDetails.splice(0, billListVm.billDetails.length);
                    billListVm.billDetails.pushArray(result);
                  }
                });
              });
            }
          },
          //修改
          handleChange: function (e, index) {
            e.stopPropagation();
            tools.throttle(runtimeParam.timeObj, function () {
              var bill = billListVm.bills[index];
              if (!bill.hasChange) {
                return;
              }
              // 需要检测账户余额是否充足
              billListVm.checkAccountBalance(function () {
                openViewAndChange(bill, 'change');
              })
            });
          },
          // 打开查看单据页面
          handleView: function (e, index) {
            e.stopPropagation();
            tools.throttle(runtimeParam.timeObj, function () {
              var bill = billListVm.bills[index];
              if (!bill.hasView) {
                return;
              }
              openViewAndChange(bill, 'view');
            });
          },
          // 作废
          handleNullify: function (e, index) {
            e.stopPropagation();
            var bill = billListVm.bills[index];
            if (!bill.hasNullify) {
              return;
            }
            if (confirm('请确认是否要进行作废操作？')) {
              bus.triggerHandler('billlist.sendAndNullifyBill', {
                bill: bill,
                className: runtimeParam.apiConfig.NullifyBillClassName,
                method: runtimeParam.apiConfig.NullifyBillMethodName,
                userID: runtimeParam.user.Ygid
              });
            }
          },
          // 发送
          handleSend: function (e, index) {
        	 
            e.stopPropagation();
            var bill = billListVm.bills[index];
            if (!bill.hasSend || !billListVm.hasSendAuth) {
              return;
            }
            if (confirm('请确认是否要进行发送操作？')) {
              bus.triggerHandler('billlist.sendAndNullifyBill', {
                bill: bill,
                className: runtimeParam.apiConfig.sendBillClassName,
                method: runtimeParam.apiConfig.sendBillMethodName,
                userID: runtimeParam.user.Ygid
              });
            }
          },
          // 返回
          back: function () {
            billListVm.bills.splice(0, billListVm.bills.length);
            tools.removeFirstChildNode(runtimeParam.main, documentNodeTree);
            runtimeParam.checkBreadcrumb();
            runtimeParam.showMenu();
            self.destroy();
          },
          //
          showFirstTimeName: function () {
            var name = '';
            switch (runtimeParam.BillType) {
              case 'qxxd':
                name = '收污时间：';
                break;
              default:
                name = '发送时间：';
                break;
            }
            return name;
          },
          //
          showSecondTimeName: function () {
            var name = '出库时间：';
            if (runtimeParam.isGYKS) {
              name = '登帐时间：';
            }
            if (runtimeParam.BillType === 'qxxd') {
              name = '发包时间：';
            }
            return name;
          }
        };
      };

      function getSearchParam() {
        return {
          startTime: billListVm.entryStartDate,
          endTime: billListVm.entryEndDate,
          sendStartDate: billListVm.sendStartDate,
          sendEndDate: billListVm.sendEndDate,
          outStartDate: billListVm.outStartDate,
          outEndDate: billListVm.outEndDate,
          BillSN: billListVm.BillSN,
          BillType: runtimeParam.BillType,
          GoodsBookID: runtimeParam.Openparm.GoodsBook,
          OutDeptAccountID: runtimeParam.ProviderDeptAccount.DeptAccountID,
          Status: billListVm.status === 'null' ? null : billListVm.status,
          InDeptAccountID: billListVm.inputAccountID,
          AdditionalReasonType: billListVm.AdditionalReasonType,
          apiConfig: runtimeParam.apiConfig,
          IsQuery: billListVm.IsQuery
        }
      }

      //  查看或者修改单据
      function openViewAndChange(bill, status) {
        tools.removeFirstChildNode(runtimeParam.main, documentNodeTree);
        new NewBill().init(runtimeParam.$main, {
          breadcrumb: JSON.parse(JSON.stringify(billListVm.breadcrumb)), //路径
          bill: JSON.parse(JSON.stringify(bill.$model)), // 单据详细信息
          OutDeptAccount: runtimeParam.ProviderDeptAccount, // 出库科室信息
          BillType: runtimeParam.BillType, // 单据类型
          Openparm: runtimeParam.Openparm,
          InDeptAccountID: runtimeParam.CurrentDeptID,
          BillStatus: status, // 单据状态
          statusStr: runtimeParam.statusStr, // 状态
          user: runtimeParam.user,
          isGYKS: JSON.parse(JSON.stringify(billListVm.isGYKS))
        });
      }

      // 初始化 状态
      function initQueryParam(param) {
        param = Object.assign({}, param, {
          startTime: param.startTime,
          endTime: param.endTime,
          isProviderDept: runtimeParam.isProviderDept,
          BillSN: billListVm.BillSN,
          deptCode: runtimeParam.CurrentDept.Ksdm
        });
        return param;
      }

      // 获取查询条件
      function getCondition(param) {
        var conditions;
        switch (runtimeParam.BillType) {
          case 'ly':
            conditions = conditionsUtils.getDrawBillConditions(param);
            break;
          case 'zy':
            if (!runtimeParam.isProviderDept) {
              param = Object.assign({}, param, {
                InDeptAccountID: runtimeParam.CurrentDeptID
              });
            }
            conditions = conditionsUtils.getTransferBillConditions(param);
            break;
          case 'jh':
            conditions = conditionsUtils.getDrawBackBillConditions(param);
            break;
          case 'sq':
            conditions = conditionsUtils.getApplyBillHeads(param);
            break;
          case 'ygsq':
              conditions = conditionsUtils.getApplyBillHeads(param);
              break;
        }
        // 供应室 领用单
        if (billListVm.isGYKS) {
          param = Object.assign({}, param, {
            BigCatID: runtimeParam.Openparm.PackageBigCat,
            DeptID: runtimeParam.CurrentDept.Ksdm,
            GroupSN: billListVm.ksGroupID
          });
          switch (runtimeParam.BillType) {
            case 'ly':
              conditions = conditionsUtils.getBillHeads(param);
              break;
            case 'dh':
              conditions = conditionsUtils.getTransBillHeads(param);
              break;
            case 'jy':
              conditions = conditionsUtils.getTransBillHeads(param);
              break;
            case 'qxxd':
              conditions = conditionsUtils.getDisinfectBillHeads(param);
              break;
          }
          runtimeParam.apiConfig = getApiConfig.initBillListApiConfig(runtimeParam.isGYKS, runtimeParam.BillType, billListVm.ksGroupID);
        }
        return {
          conditions: conditions,
          param: param
        };
      }

      // init get all receive receipt
      function setApplyBillData(data) {
        data.BillSN = data.lsh;
        switch (data.zt) {
          case '1':
            data.StatusStr = 'lr';
            data.strStatus = '申请';
            setOperateBoolean(data, true, true, true, true);
            break;
          case '2':
            data.StatusStr = 'zf';
            data.strStatus = '删除';
            setOperateBoolean(data, true, false, false, false);
            break;
          case '3':
            data.StatusStr = 'fs';
            data.strStatus = '发送';
            setOperateBoolean(data, true, false, false, false);
            break;
          case '4':
            data.StatusStr = 'hz';
            data.strStatus = '汇总';
            setOperateBoolean(data, true, false, false, false);
            break;
          case '9':
            data.StatusStr = 'zf';
            data.strStatus = '作废';
            setOperateBoolean(data, true, false, false, false);
            break;
        }
      }

      function getALLReceipt(param) {
        param = initQueryParam(param);
        if (tools.validateTime(param.startTime, param.endTime) ||
          tools.validateTime(param.sendStartDate, param.sendEndDate) ||
          tools.validateTime(param.outStartDate, param.outEndDate)) {
          tools.handleError('请查询三个月以内的数据');
          return;
        }

        runtimeParam.apiConfig = param.apiConfig;

        var __ret = getCondition(param);
        var conditions = __ret.conditions;

        runtimeParam.loadIndex = layer.load();

        api.getBills({
          className: runtimeParam.apiConfig.getBillsClassName,
          method: runtimeParam.apiConfig.getBillsMethodName,
          condition: JSON.stringify(conditions)
        }).then(function (jsonResult) {

          if (jsonResult.issuccess !== 0) {
            return Promise.reject(jsonResult.message);
          }

          var result = JSON.parse(jsonResult.result);

          // 设置 每个数据项的 的操作设置
          // 并且设置 每个数据项的状态显示 及颜色显示
          result.forEach(function (data) {
            if (runtimeParam.BillType === 'sq' || runtimeParam.BillType === 'ygsq') {
              setApplyBillData(data);
            } else {
              setOperate(data);
              data.strStatus = billListVm.statusStr[data.StatusStr]; // 中文状态
              switch (runtimeParam.BillType) {
                case 'qxxd':
                  if (data.StatusStr === 'sh')
                    data.StatusStr = 'fb';
                  if (data.StatusStr === 'fs')
                    data.StatusStr = 'jz';
                  break;
                case 'dh':
                case 'jy':
                  if (data.StatusStr === 'sh')
                    data.StatusStr = 'jz';
                  break;
              }
            }
          });

          result.sort(function (value1, value2) {
            var data1 = parseInt(value1.BillSN);
            var data2 = parseInt(value2.BillSN);
            return data1 > data2 ? -1 : 1;
          });

          billListVm.bills.splice(0, billListVm.bills.length);
          billListVm.bills.pushArray(result);
          result = null;
          layer.close(runtimeParam.loadIndex);

        })['catch'](function (ex) {
          layer.close(runtimeParam.loadIndex);
          tools.handleError(ex);
        });
      }

      // 设置按钮是否可用
      function setOperateBoolean(data, hasView, hasChange, hasSend, hasNullify) {
        data.hasView = hasView;
        data.hasChange = hasChange;
        data.hasSend = hasSend;
        data.hasNullify = hasNullify;
      }

      // 设置操作选项
      function setOperate(data) {
        setOperateBoolean(data, true, false, false, false);
        switch (data.StatusStr) {
          case 'zf':
            setOperateBoolean(data, true, false, false, false);
            break;
          case 'lr':
            // 转移单下 登录科室为 出库科室
            if (runtimeParam.BillType === 'zy' && billListVm.currentDept.DeptAccountID === data.OutDeptAccountID) {
              setOperateBoolean(data, true, true, true, false);
            } else {
              setOperateBoolean(data, true, true, true, true);
            }
            if (runtimeParam.BillType === 'dh' || runtimeParam.BillType === 'qxxd' || runtimeParam.BillType === 'jy') {
              setOperateBoolean(data, true, true, true, false);
            }
            break;
          case 'fs':
            if (runtimeParam.BillType === 'ly' && billListVm.currentDept.DeptAccountID === data.InDeptAccountID) {
              setOperateBoolean(data, true, false, false, false);
            } else if (runtimeParam.BillType === 'ly' && billListVm.currentDept.DeptAccountID === data.OutDeptAccountID) {
              setOperateBoolean(data, true, false, false, true);
            }
            // 转移单 只有供应科室 才能作废
            if (runtimeParam.BillType === 'zy' && billListVm.currentDept.DeptAccountID === runtimeParam.ProviderDeptAccount.DeptAccountID) {
              setOperateBoolean(data, true, false, false, true);
            }
            // 缴回单 只有供应科室 才能作废
            if (runtimeParam.BillType === 'jh' && billListVm.currentDept.DeptAccountID === runtimeParam.ProviderDeptAccount.DeptAccountID) {
              setOperateBoolean(data, true, false, false, true);
            }
            // 供应科 只有中心供应科才能发送
            if (billListVm.isGYKS && billListVm.currentDept.DeptAccountID === runtimeParam.ProviderDeptAccount.DeptAccountID) {
              setOperateBoolean(data, true, false, false, true);
              break;
            }
            // 调换单 和 器械消毒单
            if (runtimeParam.BillType === 'dh') {
              setOperateBoolean(data, true, false, false, true);
            }
            // 借用单
            if (runtimeParam.BillType === 'jy' || runtimeParam.BillType === 'qxxd') {
              setOperateBoolean(data, true, false, false, false);
            }
            break;
          default:
            setOperateBoolean(data, true, false, false, false);
            break;
        }
      }

      // init data control
      function initDateControl() {
        setTimeout(function () {
          for (var i = 0, len = runtimeParam.dataIdArr.length; i < len; i++) {
            (function (i) {
              if (document.querySelector(runtimeParam.dataIdArr[i])) {
                laydate({
                  elem: runtimeParam.dataIdArr[i]
                });
              }
            }(i));
          }
        }, 100);
      }

      // init get bills
      function getBills(Openparm, currentDeptAccountID) {

        // 先加载科室信息
        api.getOutDTODept({
          className: 'OrganizationManager',
          method: 'GetOutDTODept',
          ksdm: Openparm.ProviderDept
        }).then(function (jsonResult) {

          if (jsonResult.issuccess === 0) {
            (function () {
              runtimeParam.ProviderDeptAccount = JSON.parse(jsonResult.result);
              // 判断 是否是 供应科室的登录（设备科，库房，供应科）
              runtimeParam.isProviderDept = (runtimeParam.ProviderDeptAccount.DeptAccountID === currentDeptAccountID);
              billListVm.isProviderDept = runtimeParam.isProviderDept;

              // 这里判断 出库科室 和 登录科室id是否相同
              if (runtimeParam.isProviderDept || runtimeParam.BillType === 'zy') {
                billListVm.inputAccount = '';
                billListVm.inputAccountID = '';
              } else {
                billListVm.inputAccount = runtimeParam.CurrentDept.Ksmc;
                billListVm.inputAccountID = runtimeParam.CurrentDept.DeptAccountID;
              }

              getALLReceipt(getSearchParam());

              // 发布个事件 刷新 表格
              if (runtimeParam.isRefreshEventInit) {
                bus.unbind('billlist.refreshBillsTable'); //消除事件
                bus.on("billlist.refreshBillsTable", function () {
                  getALLReceipt(getSearchParam());
                });
                runtimeParam.isRefreshEventInit = false;
              }
            }());
          }

        })['catch'](function (ex) {
          tools.handleError(ex)
        });
      }

      // 验证权限
      function checkAuth(Openparm) {
        if (Openparm.Authority.indexOf('Input') !== -1 || Openparm.Authority.indexOf('input') !== -1) { // 需要设置 权限
          billListVm.hasInputAuth = true;
        }
        if (Openparm.Authority.indexOf('Send') !== -1 || Openparm.Authority.indexOf('send') !== -1) {
          billListVm.hasSendAuth = true;
        }
      }

      function initSearchStatus() {
        billListVm.showKsGroup = false;
        billListVm.showBillSN = false;
        switch (runtimeParam.BillType) {
          case 'ly':
            billListVm.inputAccountLabelName = '入库科室账户：';
            break;
          case 'zy':
            billListVm.inputAccountLabelName = '入库科室账户：';
            break;
          case 'jh':
            billListVm.inputAccountLabelName = '出库科室账户：';
            break;
          case 'dh':
          case 'jy':
            billListVm.inputAccountLabelName = '选择科室：';
            billListVm.showKsGroup = true;
            break;
          case 'qxxd':
            billListVm.inputAccountLabelName = '申请科室：';
            billListVm.showBillSN = true;
            break;
        }

        if (runtimeParam.Openparm.IsQuery) {
          if (billListVm.BillType !== 'dh' && billListVm.BillType !== 'jy') {
            billListVm.showQuery = true;
          }
          billListVm.showBillSN = true;
          billListVm.IsQuery = true;
        }
      }

      function initBillVm(billListVm, runtimeParam) {

        billListVm.entryStartDate = tools.getYesterday();
        billListVm.entryEndDate = tools.getTomorrow();
        if (runtimeParam.BillType !== 'qxxd') {
          billListVm.sendStartDate = tools.getYesterday();
          billListVm.sendEndDate = tools.getTomorrow();
        }

        billListVm.isGYKS = runtimeParam.isGYKS; // 判断是否是供应科室的领用单
        if(runtimeParam.BillType==='ygsq'){
        	 billListVm.BillType = 'sq';
        }else{
        	billListVm.BillType = runtimeParam.BillType;
        }
       

        billListVm.currentDept = JSON.parse(localStorage.getItem('deptInfo'));
        billListVm.breadcrumb = runtimeParam.breadcrumb; // 路径
        billListVm.status = 'null'; // 状态
        billListVm.AdditionalReasonType = 'zc'; // 来源
        billListVm.BillSN = ''; // 来源
        billListVm.ksGroup = ''; // 科室组

        // 清除 入库选择
        billListVm.$watch('inputAccount', function (data) {
          if (data === '') {
            billListVm.inputAccountID = '';
          }
        });

        // 清除 科室组合
        billListVm.$watch('ksGroup', function (data) {
          if (data === '') {
            billListVm.ksGroupID = '';
          }
        });

        // init status
        getVmConfig.setStatus(billListVm, runtimeParam);
      }

      this.init = function ($main, param) {
        // 先调用 destroy 方法 可以防止新建单据页面出现的重新加载的bug
        self.destroy();

        runtimeParam = getRuntimeParam();
        runtimeParam = Object.assign(runtimeParam, param);
        runtimeParam.user = JSON.parse(localStorage.getItem('currentUser')) || {};
        // var dataIdArr = ['#entryStartDate', '#entryEndDate', '#sendStartDate', '#sendEndDate', '#outStartDate', '#outEndDate'];
        runtimeParam.dataIdArr = ['#entryStartDate', '#entryEndDate', '#sendStartDate', '#sendEndDate', '#outStartDate', '#outEndDate'];
        runtimeParam.CurrentDeptID = param.InDeptAccountID; // 当前科室ID
        runtimeParam.CurrentDept = param.InDeptAccount; // 当前科室
        runtimeParam.$main = $main;
        runtimeParam.main = runtimeParam.$main.get(0);
        runtimeParam.isRefreshEventInit = true;
        runtimeParam.isGYKS = !!runtimeParam.Openparm.PackageBigCat;
        runtimeParam.apiConfig = getApiConfig.initBillListApiConfig(runtimeParam.isGYKS, runtimeParam.BillType);
        runtimeParam.statusStr = {};

        $main.append(htmlTemp);
        var vmConfig = getVmOption();
        // 通过不同的单据类型 来设定表格的 列名 和 值
        vmConfig.columnNames = getVmConfig.getBillTableColumnNames(runtimeParam.isGYKS, runtimeParam.BillType).concat();
        vmConfig.columnValueNames = getVmConfig.getBillTableColumnValueNames(runtimeParam.isGYKS, runtimeParam.BillType).concat(); // 获取表格列名
        vmConfig.detailColumnNames = getVmConfig.getNewBillTableColumnNames(runtimeParam.isGYKS, runtimeParam.BillType).concat(); // 获取表格列名
        // 干掉操作列
        vmConfig.detailColumnNames.splice(vmConfig.detailColumnNames.length - 1, 1);
        vmConfig.detailColumnValueNames = getVmConfig.getNewBillTableColumnValueNames(runtimeParam.isGYKS, runtimeParam.BillType).concat(); // 获取表格列名

        vmConfig = Object.assign({}, vmConfig, {
          operateCustomEvent: {
            handleView: vmConfig.handleView,
            handleChange: vmConfig.handleChange,
            handleSend: vmConfig.handleSend,
            handleNullify: vmConfig.handleNullify
          }
        });
        vmConfig.statusArr.splice(0, vmConfig.statusArr.length);
        vmConfig.statusArr = getVmConfig.getStatusArr(runtimeParam.BillType);

        billListVm = tools.initAvalonVm(avalon, vmConfig, ".receive-receipt");
        initBillVm(billListVm, runtimeParam);
        initDateControl(); // 初始化时间控件
        initSearchStatus(); // 初始化查询条件
        checkAuth(runtimeParam.Openparm); // 验证权限
        getBills(runtimeParam.Openparm, runtimeParam.CurrentDeptID, runtimeParam.apiConfig); // 初始化查询 先查询 供应科室账户

        // 设置颜色说明
        getVmConfig.setColorDescription(runtimeParam, billListVm);
        tools.bindDestroyMethod(self.destroy);
      };
      
      this.destroy = function () {
        bus.unbind('refreshBillsTable');
        runtimeParam = null;
        billListVm = null;
        tools.destroy(getVmOption());
      };
    };
  });